home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / lib / scale3.pro < prev    next >
Encoding:
Text File  |  1997-07-08  |  3.3 KB  |  107 lines

  1. ; $Id: scale3.pro,v 1.3 1997/01/15 03:11:50 ali Exp $
  2. ;
  3. ; Copyright (c) 1990-1997, Research Systems, Inc.  All rights reserved.
  4. ;       Unauthorized reproduction prohibited.
  5.  
  6. pro scale3,ax=ax, az=az, xrange=xr, yrange=yr, zrange=zr
  7. ;+
  8. ; NAME:
  9. ;    SCALE3
  10. ;
  11. ; PURPOSE:
  12. ;    Set up transformation and scaling for basic 3D viewing.
  13. ;
  14. ;    This procedure is similar to SURFR and SCALE3D, except that the
  15. ;    data ranges must be specified and the scaling does not vary with 
  16. ;    rotation.
  17. ;
  18. ; CATEGORY:
  19. ;    Graphics, 3D.
  20. ;
  21. ; CALLING SEQUENCE:
  22. ;    SCALE3, XRANGE = xr, YRANGE = yr, ZRANGE = zr [, AX = ax] [, AZ = az]
  23. ;
  24. ; INPUTS:
  25. ;    No plain parameters.
  26. ;
  27. ; KEYWORD PARAMETERS:
  28. ;    XRANGE:    Two-element vector containing the minimum and maximum X values.
  29. ;        If omitted, the X-axis scaling remains unchanged.
  30. ;
  31. ;    YRANGE:    Two-element vector containing the minimum and maximum Y values.
  32. ;        If omitted, the Y-axis scaling remains unchanged.
  33. ;
  34. ;    ZRANGE:    Two-element vector containing the minimum and maximum Z values.
  35. ;        If omitted, the Z-axis scaling remains unchanged.
  36. ;
  37. ;    AX:    Angle of rotation about the X axis.  The default is 30 degrees.
  38. ;
  39. ;    AZ:    Angle of rotation about the Z axis.  The default is 30 degrees.
  40. ;
  41. ; OUTPUTS:
  42. ;    No explicit outputs.  Results are stored in the system variables 
  43. ;    !P.T, !X.S, !Y.S, and !Z.S.
  44. ;
  45. ; COMMON BLOCKS:
  46. ;    None.
  47. ;
  48. ; SIDE EFFECTS:
  49. ;    The 4 by 4 matrix !P.T (the 3D-transformation system variable), 
  50. ;    receives the homogeneous transformation matrix generated by this 
  51. ;    procedure.
  52. ;
  53. ;    The axis scaling variables, !X.S, !Y.S, and !Z.S are set
  54. ;    from the data ranges.
  55. ;
  56. ; RESTRICTIONS:
  57. ;    Axonometric projections only.
  58. ;
  59. ; PROCEDURE:
  60. ;     Set the axis scaling variables from the supplied ranges, then:
  61. ;
  62. ;     1) Translate the unit cube so that the center (.5,.5,.5) is moved
  63. ;       to the origin.
  64. ;
  65. ;     2) Scale by 1/SQRT(3) so that the corners do not protrude.
  66. ;
  67. ;     3) Rotate -90 degrees about the X axis to make the +Z
  68. ;       axis of the data the +Y axis of the display.  The +Y data axis
  69. ;       extends from the front of the display to the rear.
  70. ;
  71. ;     4) Rotate about the Y axis AZ degrees.  This rotates the
  72. ;       result counterclockwise as seen from above the page.
  73. ;
  74. ;     5) Then it rotates about the X axis AX degrees, tilting the data
  75. ;       towards the viewer.
  76. ;
  77. ;     6) Translate back to the (0,1) cube.
  78. ;
  79. ;     This procedure may be easily modified to affect different rotations
  80. ;    transformations.
  81. ;
  82. ; EXAMPLE:
  83. ;    Set up a 3D transformation where the data range is 0 to 20 for each
  84. ;    of the 3 axes and the viewing area is rotated 20 degrees about the
  85. ;    X axis and 55 degrees about the Z axis.  Enter:
  86. ;
  87. ;    SCALE3, XRANGE=[0, 20], YRANGE=[0, 20], ZRANGE=[0, 20], AX=20, AZ=55 
  88. ;
  89. ; MODIFICATION HISTORY:
  90. ;    DMS, June, 1991.
  91. ;-
  92. on_error,2                      ;Return to caller if an error occurs
  93. if n_elements(ax) eq 0 then ax=30    ;Supply defaults
  94. if n_elements(az) eq 0 then az=30
  95.  
  96. if n_elements(xr) ge 2 then !x.s = [ -xr[0], 1.]  / (xr[1]-xr[0])
  97. if n_elements(yr) ge 2 then !y.s = [ -yr[0], 1.]  / (yr[1]-yr[0])
  98. if n_elements(zr) ge 2 then !z.s = [ -zr[0], 1.]  / (zr[1]-zr[0])
  99.  
  100. ;Translate to center about origin, then scale down by 1/sqrt(3)
  101. ;so that the corners don't stick out.
  102. t3d, /RESET, TRANSLATE=[-.5,-.5,-.5], SCALE=replicate(1./sqrt(3),3)
  103. t3d, ROTATE = [-90,az,0]    ;rotate so +Z axis is now +Y
  104. t3d, ROTATE = [ax,0,0]
  105. t3d, TRANSLATE = [.5, .5, .5]    ;& back to 0,1 cube
  106. end
  107.